package com.ruoyi.common.net.webSoket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Component;

/**
 * @author xumh
 * @title: WebSocketMessageUtil
 * @projectName ruoyi
 * @description: TODO
 * @date 2024/12/1813:57
 */
@Component
public class WebSocketMessageUtil {
    @Autowired(required = false)
    private SimpMessageSendingOperations simpMessageSendingOperations;

    public WebSocketMessageUtil() {
    }

    public void sendTopic(String topic, String message) {
        this.simpMessageSendingOperations.convertAndSend("/topic/" + topic, message);
    }

    public void sendToUser(String user, String message) {
        this.simpMessageSendingOperations.convertAndSendToUser(user, "/sendUser", message);
    }
}
